package com.doctor.comm;

import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Environment;
import android.os.StatFs;
import android.os.storage.StorageManager;
import android.text.TextUtils;

public class ConstConfig {

	public static final String TODAY_EVENT_FRAG="TodayEventFrag";  //今日要事
	public static final String PUBLISH_INFO_FRAG="PublishInfoFrag";  //发布信息
	public static final String WORK_ARRANGE_FRAG="WorkArrangeFrag";  //上班安排
	public static final String SCHEDULE_TIME_FRAG="ScheduleTimeFrag";  //作息时间
	public static final String MEDICAL_INFO_FRAG="MedicalInfoFrag";    //医疗信息
	public static final String DRUGS_INFO_FRAG="DrugsInfoFrag";        //药品信息
	public static final String IMMEDIATE_NOTES_FRAG="ImmediateNotesFrag";   //即时记事
	public static final String FILE_STORAGE_FRAG="FileStorageFrag";         //文件存储
	public static final String ACCOUNT_BOOK_FRAG="AccountBookFrag";         //帐目往来
	
	public static final String SEND_SMS="sendSms";
	
	//数据库表名
	public static final String DB_NAME="doctor_aide.db";
	public static final String TODAY_EVENT_TABLE="today_event";
	public static final String SCHEDULE_TIME_TABLE="schedule_time";
	public static final String MEDICAL_INFO_TABLE="medical_info";
	public static final String DRUGS_INFO_TABLE="drugs_info";
	public static final String IMMEDIATE_NOTES_TABLE="immediate_notes";
	public static final String FILE_STORAGE_TABLE="file_storage";
	public static final String ACCOUNT_BOOK_TABLE="account_book";
	public static final String PATIENT_FILE_TABLE="patient_file";
	public static final String DISEASE_RECORD_TABLE="disease_record";
	public static final String WORK_ARRANGE_TABLE="work_arrange";
	public static final String CATEGORT_TABLE="category";
	public static final String ARTICLE_TABLE="article";
	public static final String DOCTOR_TABLE="doctor";
	public static final String USER_TABLE="user_info";
	public static final String DELETED_ARTICLE_TABLE="deleted_article";
	public static final String HEALTH_MANAGER_TABLE="health_manager";
	public static final String DATA_UPDATE_RECORD_TABLE="data_update_record";
	public static final String DELETED_DOCTOR_TABLE="deleted_doctor";
	public static final String ADVANTAGE_TABLE="advantage";
	public static final String BUY_DRUGS_TABLE="buy_drugs";
	public static final String OTHER_TABLE="other";
	public static final String HOSPITAL_TABLE="hospital";
	public static final String DELETED_PATIENT_FILE_TABLE = "deleted_patient_file";
	public static final String DELETED_DISEASE_RECORD_TABLE = "deleted_disease_record";
	public static final String USER_REGION_TABLE = "region";
	
	
	
	//闹钟id基数
	public static final int BASE_ID=30000000;
	
	
	public static final String FRAG="frag";
	public static final String MODE="mode";
	public static final String ADD="add";
	public static final String MODIFY="modify";
	public static final String BEAN="bean";
	public static final String BEAN_2="bean_2";
	public static final String TABLE="table";
	public static final String ID="id";
	
	public static final int CHOOSE_PICTURE=1;
	public static final int TAKE_PICTURE=2;
	
	//图片路径做分隔符
	public static final String IMAGE_SPLIT="-_-";
	
	
	public final static int FAILED = -1;
	public final static int SUCCESS = 1;
	public final static int NET_FAILED = 2;
	
	public final static String METHOD="method";
	public final static String GET="get";
	public final static String POST="post";
	
	public final static String FINISH="finish";
	
	public final static String LOGIN_SETTING="login_setting";
	
//	public final static String IMG_FILE="/storage/sdcard0/DoctorAideImg";
	public final static String IMG_FILE=getInerCardPath()+"/DoctorAideImg";
	
	public final static String Camera_FILE=IMG_FILE+"/CameraImg";
	public final static String ARTICLE_IMG_FILE=IMG_FILE+"/ArticleImg";
	/** //外置sd卡上的视频文件
	public final static String VIDEO_FILE_OUT="/storage/sdcard1/DoctorAideVideo/VideoCache";*/
	//外置sd卡上的视频文件
	public final static String VIDEO_FILE_OUT = getExterSdPath() + "/DoctorAideVideo/VideoCache";
	//内置sd卡上的视频文件
	public final static String VIDEO_FILE_INER = getInerCardPath() + "/DoctorAideVideo/VideoCache";
	
	public final static String ARTICLE_IMG_PATH="file://"+ARTICLE_IMG_FILE+"/";
	
	public final static String DB_FILE=IMG_FILE+"/"+"DataBase";
	//存放下载的病历图片(2016/3/25添加)
	public final static String DOWNLOAD_DISEASE_RECORD_IMG_FILE = IMG_FILE + "/DiseaseRecordImg";
	public static final String URL="url";
	
	public static final String ACCOUNT_VALID="账号正常可用";
	
	
	//家庭医生的数据操作类型
	public static final int OPERATION_NULL = 0;
	public static final int OPERATION_ADD = 1;
	public static final int OPERATION_MODIFY = 2;
	public static final int OPERATION_DELETE = 3;
	
	
	/**
	 * 获取内部存储卡的路径
	 * @return
	 */
	public static String getInerCardPath(){
		String path = null;
		path = Environment.getExternalStorageDirectory().getAbsolutePath();
		return path;
	}
	
	
	/**
	 * 获取外部sd卡的路径(有多个外部sd卡的话就只获取第一个)
	 * @return
	 */
	public static String getExterSdPath() {
		String exterPath;
		List<String> pathsList = new ArrayList<String>();/**
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.GINGERBREAD) {
            StringBuilder sb = new StringBuilder();
            try {
                pathsList.addAll(new SdCardFetcher().getStoragePaths(new FileReader("/proc/mounts"), sb));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                File externalFolder = Environment.getExternalStorageDirectory();
                if (externalFolder != null) {
                    pathsList.add(externalFolder.getAbsolutePath());
                }
            }
        } else {*/
            StorageManager storageManager = (StorageManager) MyApplication.getInstance().getSystemService(Context.STORAGE_SERVICE);
            try {
                Method method = StorageManager.class.getDeclaredMethod("getVolumePaths");
                method.setAccessible(true);
                Object result = method.invoke(storageManager);
                if (result != null && result instanceof String[]) {
                    String[] pathes = (String[]) result;
                    StatFs statFs;
                    for (String path : pathes) {
                        if (!TextUtils.isEmpty(path) && new File(path).exists()) {
                            statFs = new StatFs(path);
                            if (statFs.getBlockCount() * statFs.getBlockSize() != 0) {
                                pathsList.add(path);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();/**
                File externalFolder = Environment.getExternalStorageDirectory();
                if (externalFolder != null) {
                    pathsList.add(externalFolder.getAbsolutePath());
                }*/
            }
     /**}*/
        
        if (pathsList.size() >= 2) {
        	exterPath = pathsList.get(1);
		} else {
			exterPath = "/storage/sdcard1";
		}
         return exterPath;
	}
	
	
	
	
	
}
